<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>地图展示</title>
		
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=tr1cFgHnr57lDma8FskVQHz7aNWFD03v"></script>
	</head>
	<body>
		
		
		
		        <div id="allmap"></div>
		        <input type="text" id="address" width="2000"/>

		
	</body>
</html>
<script type="text/javascript">

    var map = new BMap.Map("allmap");
    //初始化地图 默认加载北京天安门
    var point = new BMap.Point(116.331398, 39.897445);
    map.centerAndZoom(point, 16); //初始化地图，point为中心点，缩放级别为16
    //判断手机浏览器是否支持定位
    if(navigator.geolocation) {
        var geolocation = new BMap.Geolocation(); //创建定位实例
        geolocation.getCurrentPosition(showLocation, {
            enableHighAccuracy: true
        }); //enableHighAccuracy 要求浏览器获取最佳结果
    } else {
        map.addControl(new BMap.GeolocationControl()); //添加定位控件 支持定位
    }
    var gc = new BMap.Geocoder();//将坐标转换成地址

    //处理定位后的信息
    function showLocation(r) {
        if(this.getStatus() == BMAP_STATUS_SUCCESS) { //定位成功
            //新建中心点 并将地图中心移动过去
            var centerPoint = new BMap.Point(r.longitude, r.latitude);
            map.panTo(centerPoint);
            map.setCenter(centerPoint);
            gc.getLocation(centerPoint,function(rs){
                var addComp = rs.addressComponents;  
                var mapAddress = addComp.province + addComp.city + addComp.district  
                + addComp.street + addComp.streetNumber;   
                //mui.alert(mapAddress);
                var address = document.getElementById('address');
                address.value=mapAddress;
				alert(mapAddress)
                address.readOnly='readonly';

            });
            //新建标注
            var mk = new BMap.Marker(centerPoint);
            mk.disableDragging(); // 不可拖拽
            map.addOverlay(mk);
        } else {
            mui.alert('failed' + this.getStatus()); //定位失败
        }
    }
</script>

